var username=localStorage.getItem("username");
var token=localStorage.getItem("token");
var userid=localStorage.getItem("userid");
$(function(){
	var paramMap = params();
	var id = paramMap['id'];
	$("#backList").click(function(){
		var url='/buyerManage/list.do';
		tl_config.last_url=url;
		tl_config.loadToWorkArea(url);
	});
	
	$.ajax({
		type : 'GET',
		contentType : 'application/json',
		async : false,
		data : {
			orderId : id,
			token:token
		},
		url : server_url+'/rest/orderManage/getOrder.do?ran='+Math.random(),
		dataType : 'json',
		success : function(data) {
			if (data.retCode == "0000") {
				pasteData(data.data);
			} else{
				easyDialog.open({
					container:{
						header:'温馨提示',
						content:data.retMsg
					},
					autoClose : 2000
				});
			}
		}
	});
	
});

function isEmpty(data){
	if(data==null||data==undefined||data.length==0){
		return true;
	}else{
		return false;
	}
}
function pasteData(data){
	//console.log(data);
	$("#orderCode").text(data.orderCode);
	$("#orderStatusName").text(data.orderStatusName);
	$("#shipStatusName").text(data.shipStatusName);
	$("#sourceOrderNo").text(data.sourceOrderNo);
	$("#compName").text(data.buyer.compName);
	$("#consAddr").text(data.consAddr + "," +data.consignee);
	$("#payWay").text(data.payWayName);
	
	$("#payType").text(data.payTypeName);
	$("#consCarrier").text(data.consCarrier);
	$("#chargeFee").text(data.chargeFee);
	$("#shipBillCode").text(data.shipBillCode);
	$("#realCarrier").text(data.realCarrier);
	$("#remark").text(data.remark);
	

	$("<tr><td>"+(data.price - data.chargeFee)+"</td> " +
			"<td>"+0+"</td>  " +
			"<td>"+data.chargeFee+"</td>  " +
			"<td>"+ data.price+"</td>  " +
			"</tr>").appendTo($("#priceTable"));

	
	var details = data.lstOrderDetail;
	console.log(details);
	if(exist(details)){
		_.map(details,function(obj){
			$("<tr><td>"+obj.productName+"</td> " +
					"<td>"+parseFloat(obj.productNum)+"</td>  " +
					"<td>"+"吨"+"</td>  " +
					"<td>"+obj.productPrice+"</td>  " +
					"<td>"+obj.price+"</td>  " +
					"<td>"+obj.supplyVo.supplyName+"</td>  " +
					"<td>"+(obj.supplyVo.provinceName+obj.supplyVo.cityName)+"</td>  " +
					"<td>"+obj.supplyVo.resPerson+"</td>  " +
					"<td>"+obj.supplyVo.usersName+"</td>  " +
					"</tr>").appendTo($("#productTable"));
		});
	}
};
function back(){
	var url=server_url+'orderManage/list.do';
	//tl_config.last_url=url;
	tl_config.loadToWorkArea(url);
}
